﻿using System.Windows;
using System.Windows.Navigation;
using QuizzMe.Helpers;

namespace QuizzMe.Pages
{
    /// <summary>
    /// Home page
    /// </summary>
    public partial class Home : BasePage
    {
        public Home()
        {
            InitializeComponent();
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            AuthHelper.Get.OnGetParams += OnGetParams;
            base.OnNavigatedTo(e);
        }

        private void OnGetParams()
        {
            Dispatcher.BeginInvoke(() =>
                                       {
                                           var prm = AuthHelper.Get.Params;
                                           if (prm == null) return;
                                           if (prm.ContainsKey("id"))
                                               this.NavigateTo("/Quizz?id=" + prm["id"]);
                                           if (prm.ContainsKey("defy"))
                                               this.NavigateTo("/Quizz?defy=" + prm["defy"]);
                                       });
        }

        private void ButtonChooseDifficultyClick(object sender, RoutedEventArgs e)
        {
            this.NavigateTo("/Difficulty");
        }

        private void ButtonPlayQuizzThemeClick(object sender, RoutedEventArgs e)
        {
            this.NavigateTo("/Themes");
        }

        private void ButtonRulesClick(object sender, RoutedEventArgs e)
        {
            this.NavigateTo("/Rules");
        }

        private void ButtonPlayRandomQuizzClick(object sender, RoutedEventArgs e)
        {
            this.NavigateTo("/Quizz?random=true");
        }

        private void ButtonShowTopTenClick(object sender, RoutedEventArgs e)
        {
            this.NavigateTo("/TopTen");
        }
    }
}
